package com.qqtech.qquan.community.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.common.annotation.VisitAnnt;
import com.qqtech.core.common.enums.RespEnum;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.community.model.CommunityAddr;
import com.qqtech.qquan.community.model.CommunityAddrQuery;
import com.qqtech.qquan.community.model.CommunityAddrVo;
import com.qqtech.qquan.community.service.CommunityAddrService;
import com.qqtech.qquan.homemaking.model.HomemakingBase;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/community/addr")
public class CommunityAddrController extends
		BaseWebController<CommunityAddr, CommunityAddrQuery> {
	@Resource
	private CommunityAddrService communityAddrService;

	@Override
	protected BaseService<CommunityAddr> getBaseService() {
		return communityAddrService;
	}

	@VisitAnnt(type = RespEnum.LOGIN)
	@RequestMapping(value = "/findChildren")
	@ResponseBody
	public Result findChildren(@RequestBody CommunityAddrVo communityAddr) {
		Result result = new Result();
		if (communityAddr == null) {
			result.addErr("参数不能为空");
		} else if (communityAddr.getCommunityId() == null) {
			result.addErr("社区id不能为空");
		}
		if (result.checkForm()) {
			List<CommunityAddrVo> list = communityAddrService
					.queryListByParentIdCache(communityAddr.getCommunityId(),communityAddr.getId());
			result.put("list", list);
		}
		return result;
	}
	
	@VisitAnnt(type = RespEnum.LOGIN)
	@RequestMapping(value = "/isLast")
	@ResponseBody
	public Result isLast(@RequestBody CommunityAddrVo communityAddr) {
		Result result = new Result();
		if (communityAddr == null) {
			result.addErr("参数不能为空");
		} else if (communityAddr.getCommunityId() == null) {
			result.addErr("社区id不能为空");
		} else if (communityAddr.getId() == null) {
			result.addErr("id不能为空");
		}
		if (result.checkForm()) {
			CommunityAddrQuery q = new CommunityAddrQuery();
			q.setParentId(communityAddr.getId());
			q.setCommunityId(communityAddr.getCommunityId());
			int count = communityAddrService.queryCount(q);
			if (count > 0) {
				result.put("isLast", 0);
			} else {
				result.put("isLast", 1);
			}
		}
		return result;
	}
}
